package com.ayla.demo.binder

import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import com.ayla.demo.databinding.WidgetMusicBinding
import com.ayla.demo.widgets.binder.AbsItemBinder
import com.ayla.demo.widgets.holder.BinderViewHolder
import com.blankj.utilcode.util.SizeUtils

class MusicBinder: AbsItemBinder<Int, WidgetMusicBinding>() {

    override fun onCreateViewBinding(
        parent: ViewGroup,
        inflater: LayoutInflater,
        viewType: Int
    ): WidgetMusicBinding {
        val binding = WidgetMusicBinding.inflate(inflater)
        val width = (parent.width - (3 * SizeUtils.dp2px(10f))) / 2
        Log.i("hzw", "2X4 => dp10 = ${SizeUtils.dp2px(10f)}, pWidth = ${parent.width}, width = $width")
        val params =  RecyclerView.LayoutParams(width, RecyclerView.LayoutParams.MATCH_PARENT)
        binding.textView.layoutParams = params
        return binding
    }

    override fun convert(holder: BinderViewHolder<WidgetMusicBinding>, data: Int) {
        holder.binding.textView.text = "${holder.bindingAdapterPosition} - $data"
    }

    override fun onDrag(holder: BinderViewHolder<WidgetMusicBinding>) {
        holder.binding.view.isVisible = true
    }

    override fun onEnd(holder: BinderViewHolder<WidgetMusicBinding>) {
        holder.binding.view.isVisible = false
    }
}